<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of Url
 *
 * @author Костя
 */
class Url {
    
    var $url;
    var $url_array;
    
    function __construct($url) {
        $this->url = $url;
    }
    
    public function parseUrl(){
        $url=$this->url;
        $this->url_array = explode('/', $url);
        $url = $this->clearUrlConstruct($this->url_array);
        $_SERVER['REQUEST_URI'] = $url;
        return $url;
    }
    
    private function clearUrlConstruct($array)
    {
        $new = Array();
        foreach($array as $id => $link){
            if(trim($link) != '')
            {
                $new[]=trim(urldecode($link));
            }
        }
        
        if(count($new)==0){
            return '/';
        }else{
            $url_r = implode('/', $new);
            $url_r = str_replace(' ', '', $url_r);
            return preg_replace('/\/{2,}/', '/', '/' . $url_r . '/');
        }
    }
    
    
}

?>
